package database;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.*;

public class Database extends HttpServlet {

	private static final String HOST = "localhost";
	private static final String PORT = "3306";
	private static final String DATABASE = "ualbanybook";
	private static final String USER = "root";
	private static final String PASSWORD = "isaac16";
	protected Connection connection;

	public Database() {
		super();
	}

	public void connect() {
	      try
	      {
	         // Override the host if DB_SERVER_HOST is set.
	         String host = System.getenv("DB_SERVER_HOST");
	         if (host == null) host = HOST;
	
	         Class.forName("com.mysql.jdbc.Driver");
	
	         String url =  "jdbc:mysql://" + host + ":" + PORT + "/" + DATABASE;
	         connection = DriverManager.getConnection(url, USER, PASSWORD);
	      }
	      catch (Exception e) { System.err.println(e); }
	   }

	public void disconnect() {
	      try { connection.close(); }
	      catch (Exception e) { System.err.println(e); }
	   }

}